package me.ele.enan.service;

import me.ele.enan.helper.DatabaseHelper;
import me.ele.enan.model.Customer;
import me.ele.enan.util.PropsUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;

/**
 * Created by Administrator on 2015/10/8.
 */
public class CustomerService {
    private static final Logger log = LoggerFactory.getLogger(CustomerService.class);

    public List<Customer> getCustomerList() {
//        Connection conn = DatabaseHelper.getConnection();
//        try {
//            List<Customer> customerList = new ArrayList<Customer>();
            String sql = "SELECT * FROM customer";
//            conn = DatabaseHelper.getConnection();
//            PreparedStatement ps = conn.prepareStatement(sql);
//            ResultSet rs = ps.executeQuery();
//            while (rs.next()) {
//                Customer c = new Customer();
//                c.setId(rs.getLong("id"));
//                c.setName(rs.getString("name"));
//                c.setContact(rs.getString("contact"));
//                c.setTelephone(rs.getString("telephone"));
//                c.setEmail(rs.getString("email"));
//                c.setRemark(rs.getString("remark"));
//                customerList.add(c);
//            }
//            return customerList;
            return DatabaseHelper.queryEntityList(Customer.class, sql);
//        } catch (Exception e) {
//            log.error(e.getMessage(), e);
//        } finally {
//            DatabaseHelper.closeConnection(conn);
//        }
//        return null;
    }

    public List<Customer> getCustomerList(String keyword) {
        return null;
    }

    public Customer getCustomer(long id) {
        return null;
    }

    public boolean createCustomer(Map<String, Object> fieldMap) {
        return DatabaseHelper.insertEntity(Customer.class, fieldMap);
    }

    public boolean updateCustomer(long id, Map<String, Object> fieldMap) {
        return DatabaseHelper.updateEntity(Customer.class, id, fieldMap);
    }

    public boolean deleteCustomer(long id) {
        return DatabaseHelper.deleteEntity(Customer.class, id);
    }
}
